package com.neu.service;

import com.neu.mapper.UserMapper;
import com.neu.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService{

	@Autowired
	private UserMapper userMapper;
	
	public User getUser(String userName) {
		return userMapper.findUserByName(userName);
	}

	public User getUserById(int id) {
		return userMapper.findUserById(id);
	}

	/**
	 * 登录验证方法的实现
	 */
	public boolean isLogin(User user) {
		//代码编写处
		User userByName = userMapper.findUserByName(user.getUserName());
		if (userByName.getPassword().equals(user.getPassword())){
			return true;
		}else{
			return false;
		}
	}

	public List<User> getUsers() {
		return userMapper.findAll();
	}

	@Override
	public int addUser(User user) {
		return userMapper.addUser(user);
	}

	@Override
	public int updateUser(User user) {
		return userMapper.updateUser(user);
	}

	@Override
	public int deleteUserById(int id) {
		return userMapper.deleteUserById(id);
	}

}
